home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / libg_261.zip / libg_261 / libg++ / src / builtin.h < prev    next >
C/C++ Source or Header  |  1994-07-22  |  3KB  |  145 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2.  
  3. /* 
  4. Copyright (C) 1988, 1992 Free Software Foundation
  5.     written by Doug Lea (dl@rocky.oswego.edu)
  6.  
  7. This file is part of the GNU C++ Library.  This library is free
  8. software; you can redistribute it and/or modify it under the terms of
  9. the GNU Library General Public License as published by the Free
  10. Software Foundation; either version 2 of the License, or (at your
  11. option) any later version.  This library is distributed in the hope
  12. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  13. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  14. PURPOSE.  See the GNU Library General Public License for more details.
  15. You should have received a copy of the GNU Library General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. /*
  21.   arithmetic, etc. functions on built in types
  22. */
  23.  
  24.  
  25. #ifndef _builtin_h
  26. #ifdef __GNUG__
  27. #pragma interface
  28. #endif
  29. #define _builtin_h 1
  30.  
  31. #include <stddef.h>
  32. #include <std.h>
  33. #include <math.h>
  34.  
  35. #ifdef __GNUG__
  36. #define _VOLATILE_VOID volatile void
  37. #else
  38. #define _VOLATILE_VOID void
  39. #endif
  40.  
  41. typedef void (*one_arg_error_handler_t)(const char*);
  42. typedef void (*two_arg_error_handler_t)(const char*, const char*);
  43.  
  44. long         gcd(long, long);
  45. long         lg(unsigned long); 
  46. double       pow(double, long);
  47. long         pow(long, long);
  48.  
  49. extern "C" double       start_timer();
  50. extern "C" double       return_elapsed_time(double last_time = 0.0);
  51.  
  52. char*        dtoa(double x, char cvt = 'g', int width = 0, int prec = 6);
  53.  
  54. unsigned int hashpjw(const char*);
  55. unsigned int multiplicativehash(int);
  56. unsigned int foldhash(double);
  57.  
  58. extern _VOLATILE_VOID default_one_arg_error_handler(const char*);
  59. extern _VOLATILE_VOID default_two_arg_error_handler(const char*, const char*);
  60.  
  61. extern two_arg_error_handler_t lib_error_handler;
  62.  
  63. extern two_arg_error_handler_t 
  64.        set_lib_error_handler(two_arg_error_handler_t f);
  65.  
  66.  
  67. #if !defined(IV)
  68.  
  69. #if ! _G_MATH_H_INLINES /* hpux and SCO define this in math.h */
  70. inline double abs(double arg) 
  71. {
  72.   return (arg < 0.0)? -arg : arg;
  73. }
  74. #endif
  75.  
  76. inline float abs(float arg) 
  77. {
  78.   return (arg < 0.0)? -arg : arg;
  79. }
  80.  
  81. inline short abs(short arg) 
  82. {
  83.   return (arg < 0)? -arg : arg;
  84. }
  85.  
  86. inline long abs(long arg) 
  87. {
  88.   return (arg < 0)? -arg : arg;
  89. }
  90.  
  91. inline int sign(long arg)
  92. {
  93.   return (arg == 0) ? 0 : ( (arg > 0) ? 1 : -1 );
  94. }
  95.  
  96. inline int sign(double arg)
  97. {
  98.   return (arg == 0.0) ? 0 : ( (arg > 0.0) ? 1 : -1 );
  99. }
  100.  
  101. inline long sqr(long arg)
  102. {
  103.   return arg * arg;
  104. }
  105.  
  106. #if ! _G_MATH_H_INLINES /* hpux and SCO define this in math.h */
  107. inline double sqr(double arg)
  108. {
  109.   return arg * arg;
  110. }
  111. #endif
  112.  
  113. inline int even(long arg)
  114. {
  115.   return !(arg & 1);
  116. }
  117.  
  118. inline int odd(long arg)
  119. {
  120.   return (arg & 1);
  121. }
  122.  
  123. inline long lcm(long x, long y)
  124. {
  125.   return x / gcd(x, y) * y;
  126. }
  127.  
  128. inline void (setbit)(long& x, long b)
  129. {
  130.   x |= (1 << b);
  131. }
  132.  
  133. inline void clearbit(long& x, long b)
  134. {
  135.   x &= ~(1 << b);
  136. }
  137.  
  138. inline int testbit(long x, long b)
  139. {
  140.   return ((x & (1 << b)) != 0);
  141. }
  142.  
  143. #endif
  144. #endif
  145.